use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::Kaufman

///
///  参见[KAMA](https://www.marketvolume.com/technicalanalysis/kama.asp)
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct KAMA {
    ///  1 signal
    /// if filter_period is less or equal than 0, then returns signal when KAMA crosses source value.
    /// When source crosses KAMA upwards, returns full buy signal.
    /// When source crosses KAMA downwards, returns full sell signal.
    /// Otherwise returns no signal.
    ///
    ///if filter_period is greater than 1, it uses same cross between source and KAMA, but with additional filtering using standard deviation.
    pub signal0: Option<IndicatorActionWrap>,

    /// 1 value
    /// KAMA value
    /// Range of KAMA values is the same as the range of the source values.
    pub kama: ValueType,
}

/// Configuration
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct KAMAConfig {
    ///period1: PeriodType
    ///Volatility calculation period. Default is 10.
    ///
    ///Range in [1; PeriodType::MAX).
    ///
    pub period1: PeriodType,

    ///period2: PeriodType
    ///Fast period. Default is 2.
    ///
    ///Range in [1; period3).
    ///
    pub period2: PeriodType,

    ///period3: PeriodType
    ///Slow period. Default is 30.
    ///
    ///Range in (period2; PeriodType::MAX).
    ///
    pub period3: PeriodType,

    ///filter_period: PeriodType
    ///Filter period. Default is 10.
    ///
    ///Range in [0; PeriodType::MAX)
    ///
    pub filter_period: PeriodType,

    ///square_smooth: bool
    ///Apply double smoothing. Default is true.
    ///
    pub square_smooth: bool,

    ///k: ValueType
    ///Standard deviation multiplier. Default is 0.3.
    ///
    ///Range in (0.0; +inf)
    pub k: ValueType,
    // pub source: Source,
    //source: Source
    //Source type. Default is Close
}

impl Default for KAMAConfig {
    fn default() -> Self {
        Self {
            period1: 10,
            period2: 2,
            period3: 30,
            filter_period: 10,
            square_smooth: true,
            k: 0.3,
        }
    }
}
